package com.fbt.andon.tool;


import com.fbt.andon.controller.DaysController;
import com.fbt.andon.domain.BoardStation;
import com.fbt.andon.domain.Days;
import com.fbt.andon.mapper.DaysMapper;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class XMLParse {



    public  static void analysis(String msg) {
        BoardStation boardStation = new BoardStation();
//                      创建解析对象
       SAXReader reader = new SAXReader();//创建读取文件内容对象
       try {
        Document dom = DocumentHelper.parseText(msg);
        Element root = dom.getRootElement();
       // 解析入口   解析
           System.out.println(root.element("name").getText());

        boardStation.setWorkName(root.element("String").getText());
        boardStation.setProductSum(Integer.valueOf(root.element("Integer").getText()));
        boardStation.setOkCount(Integer.valueOf(root.element("Integer2").getText()));
        System.out.println(boardStation.getWorkName());

    } catch (
       DocumentException e) {
         e.printStackTrace();
    }

    }
    public static Days  analysis1(String msg) throws ParseException {
        Days days = new Days();
        //       创建解析对象
        SAXReader reader = new SAXReader();//创建读取文件内容对象
        try {
            Document dom = DocumentHelper.parseText(msg);
            Element root = dom.getRootElement();
            // 解析入口   解析
//            System.out.println(root.element("name").getText());
//            Days.setWorkName(root.element("String").getText());
            String amountDate = root.element("string").getText();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
            Date date = simpleDateFormat.parse(amountDate);
            days.setAmountDate(date);
            days.setFactAmount(Integer.valueOf(root.element("Integer1").getText()));
            days.setDayNg(Integer.valueOf(root.element("Integer2").getText()));
            System.out.println(days.toString());
            return days;
        } catch (
                DocumentException e) {
            e.printStackTrace();
        }
       return days;
    }

}